const app = getApp()
Page({
  data: {
    isIphoneX:false,
    showPrice:0,
    currentSpecificationId: 0,
    showBuyMarket: false,
    goodsId: null,
    goodstype: true,
    marketDetail: {}
  },
  onLoad: function (options) {
    this.data.goodsId = options.id
    if (options.goodstype == 0) {
      this.setData({
        goodstype: false
      })
    } else {
      this.setData({
        goodstype: true
      })
    }
    let modelmes = wx.getStorageSync('modelmes');
    let isIphoneX = app.globalData.isIphoneX;
    this.setData({
     isIphoneX: isIphoneX
    })
    console.log(typeof (this.data.goodstype))
    this.getGoodsDetail()
  },
  onClose(){
    this.setData({
      showBuyMarket: false
    })
  },
  showBuyPop() {
    this.setData({
      showBuyMarket: true
    })
  },
  closeBuyPop() {
    this.setData({
      showBuyMarket: false
    })
  },
  getGoodsDetail() {
    let _this = this;
    app.util.request({
      url: "api/mall/findById",
      method: "get",
      data: {
        id: _this.data.goodsId
      },
      success(response) {
        console.log(response)
        if (response.data.code == 0) {
          _this.setData({
            currentSpecificationId: response.data.data.allSpecification.length ? response.data.data.allSpecification[0].id : 0,
            showPrice:response.data.data.allSpecification.length ? response.data.data.allSpecification[0].price:response.data.data.price,
            marketDetail: response.data.data
          })
          let content = response.data.data.introduce;
          var WxParse = require('../../../utils/wxParse/wxParse.js');
          WxParse.wxParse('article', 'html', content, _this, 10);
        }
      }
    })
  },
  chooseSpecification(e) {
    let specification = this.data.marketDetail.allSpecification[e.currentTarget.dataset.index]
    this.setData({
      currentSpecificationId: specification.id,
      showPrice: specification.price
    })
  },
  toCreateOrder() {
    let url = '/pages/order/create-order/create-order?id=' + this.data.goodsId + '&specificationId=' + this.data.currentSpecificationId + '&type=0'
    wx.navigateTo({
      url: url,
    })
  },
})
